<!--标记唛码-->
<template>
    <Modal :value="value" @input="handleInput" width="746" class="col-2" :closable="false">
        <div slot="header">
            标记唛码
            <Icon class="f-fr" type="ios-close" @click="closeModal"/>
        </div>
        <Form class="clearfix">
            <Input :disabled="editORshow" v-model="markNo" type="textarea" :rows="4" :maxlength="400" @on-blur="fmtMarkNo"/>
        </Form>
        <!-- eslint-disable-next-line vue/no-parsing-error -->
        <div>（{{markNoLen < 400 ? markNoLen : 400}}字节）</div>
        <div slot="footer">
            <Button style="display: none" type="default"></Button>
            <Button type="primary" @click="saveMarkerCode">保存</Button>
        </div>
    </Modal>
</template>

<script>
import { getStrBytesLen, getStrByBytesLen } from '@/libs/tools'
export default {
    name: 'MarkerCodeModal',
    props: {
        value: {
            default: false,
            type: Boolean
        },
        markerCodeParams: {
            default: function () {
                return {
                    markNo: 'N/M',
                    editORshow: false
                }
            },
            type: Object
        }
    },
    data () {
        return {
            markerCodeModal: false,
            editORshow: '',
            markNo: 'N/M' // 标记唛码 ,
        }
    },
    computed: {
        markNoLen () {
            return getStrBytesLen(this.markNo || '')
        }
    },
    created () {
        this.editORshow = this.markerCodeParams.editORshow
        this.markNo = this.markerCodeParams.markNo
    },
    methods: {
        fmtMarkNo () {
            if (this.markNoLen > 400) {
                this.markNo = getStrByBytesLen(this.markNo, 400)
            }
        },
        closeModal () {
            this.handleInput(false)
        },
        handleInput (v) {
            this.$emit('input', v)
        },
        saveMarkerCode () {
            let res = this.markNo ? this.markNo : 'N/M'
            this.$emit('saveMarkerCode', res)
            this.closeModal()
        }
    }
}
</script>
